<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.prime.com.tr/ui"
      xmlns:c="http://java.sun.com/jsp/jstl/core">
	<ui:composition template="/templates/padrao.xhtml">
		<ui:define name="barraTitulo">Cadastro de Servi&ccedil;o:</ui:define>
			<ui:define name="conteudo" >
					
				<p:tabView>
					<p:tab title="Manuten&ccedil;&atilde;o">
						<h:form id="form">
							<p:dialog header="Mensagem" id="dialog1" widgetVar="dialog" fixedCenter="true" modal="true" visible="#{facesContext.maximumSeverity != null}">
					   			<p:messages/>                     
							</p:dialog>
							<h:panelGrid columns="2" columnClasses="width150 alinhaDir, width500" >							
																
								<h:outputText value="Tipo Servi&ccedil;o: " styleClass="alinhaDir"/>							
								<h:selectOneMenu value="#{controleServico.codigoTipoServicoPesquisa}"  required="true" >
									<f:selectItem var="TipoServico" itemLabel="selecione" itemValue="0"/>  
					            	<f:selectItems value="#{controleServico.listaTipoServico}" var="TipoServico" itemLabel="#{TipoServico.descricao}" itemValue="#{TipoServico.codigoTipoServico}" />
								</h:selectOneMenu>			
								<h:outputText value=" Servi&ccedil;o: " styleClass="alinhaDir"/>							
								<h:inputText value="#{controleServico.descricaoPesquisa}" styleClass="textfield" size="60" />						
								<h:outputText value="Cliente:" styleClass="alinhaDir"/>
								<h:column>		
									<h:inputText value="#{controleServico.pesquisaNomeCliente}" /> 
									<h:outputText value=" CPF / CNPJ " styleClass="alinhaDir"/>
									<h:inputText value="#{controleServico.pesquisaCPFCNPJCliente}"/>	
								</h:column>
																
								
							</h:panelGrid>
							<h:panelGrid styleClass="alinhaMeio">								
								<h:column headerClass="alinhaDir" >
									<h:commandLink action="#{controleServico.adicionar}" class="btnAcoes">
										<h:graphicImage url="/images/botoes/btnNovo.png" styleClass="hand" />
									</h:commandLink>
									<h:commandLink action="#{controleServico.limpar}" class="btnAcoes">
										<h:graphicImage url="/images/botoes/btnLimpar.png" styleClass="hand" />
										<f:ajax render=":form"/>
									</h:commandLink>
									<h:commandLink action="#{controleServico.pesquisar}" class="btnAcoes">
										<h:graphicImage url="/images/botoes/btnPesquisar.png" styleClass="hand"  />
										<f:ajax render=":lista" execute="@form"/>								
									</h:commandLink>									
								</h:column>
							</h:panelGrid>
						</h:form>
					</p:tab>
				</p:tabView>
				<h:form id="lista" >
				<p:dataTable value="#{controleServico.lista}" 
				             id="id_Lista"
				             var="servico" 
				             paginator="true" 
				             rows="10" 
				             dynamic="true" 
				             rendered="#{not empty controleServico.lista}" 
							 firstPageLinkLabel="Primeiro"
				             previousPageLinkLabel="Anterior"
				             nextPageLinkLabel ="Pr&oacute;ximo"
				             lastPageLinkLabel="&Uacute;ltima"
				             emptyMessage="Nenhum resgistro encontrado"
				             errorMessage="Ocorreu um erro"	    			             
				             selectionMode="single">
				    <p:column>
						<f:facet name="header">
							<h:outputText value="Tipo Servi&ccedil;o" />
						</f:facet>
						<ui:repeat var="tipoServico" value="#{servico.tipoServicos}" varStatus="i">
							<h:outputText value="#{tipoServico.descricao}" />
							<h:outputText value=" / " rendered="#{servico.totalTipoServicos > i.index+1}"/>
						</ui:repeat>
					</p:column>
					<p:column sortBy="#{servico.descricao}" styleClass="width5" >
						<f:facet name="header">
							<h:outputText value="Servi&ccedil;o" />
						</f:facet>
						<h:outputText value="#{servico.descricao}" />
					</p:column>
					<p:column styleClass="width5" >
						<f:facet name="header">
							<h:outputText value="Cliente" />
						</f:facet>
						<h:outputText value="#{servico.cliente.nome}" />
					</p:column>
					<p:column styleClass="width5" >
						<f:facet name="header">
							<h:outputText value="CPF / CNPJ" />
						</f:facet>
						<h:outputText value="#{servico.cliente.CPF_CNPJ}" />
					</p:column>
					
					<p:column styleClass="width40" >
						<f:facet name="header">
							<h:outputText value="Data"  styleClass="width30"/>
						</f:facet>
						<h:outputText value="#{servico.dataAnuncio}" />
					</p:column>
					
					         				             
                 
					<p:column resizable="true" styleClass="width80">
						<f:facet name="header">
							<h:outputText value="A&ccedil;&atilde;o" /> 
						</f:facet>
						<h:commandLink action="#{controleServico.alterar}">  
							<h:graphicImage url="/images/marcadores/editar.png"  alt="Alterar Ve&iacute;culo"/>  
							<f:setPropertyActionListener target="#{controleServico.servico}" value="#{servico}" />
						</h:commandLink>
						<p:commandLink update="lista" oncomplete="dlg.show();">  
							<h:graphicImage url="/images/marcadores/excluir.png" alt="Excluir Ve&iacute;culo"/>  
							<f:setPropertyActionListener target="#{controleServico.servico}" value="#{servico}" />
						</p:commandLink>
                    	</p:column>
				</p:dataTable>
				<p:dialog header="Confirma&ccedil;&atilde;o" width="300" fixedCenter="true" widgetVar="dlg" visible="false">  
					<h:panelGrid columns="2" style="margin-bottom:10px">
						<h:column>   
							<h:outputLabel  value="Deseja Excluir?" />
						</h:column>
						<h:column >
							<p:commandButton value="Sim" action="#{controleServico.excluir}" update="id_Lista" oncomplete="dlg.hide();" />  
							<p:commandButton value="Nao" update="form" oncomplete="dlg.hide();"/>
						</h:column>  
					</h:panelGrid>  
				</p:dialog>
			</h:form>
		</ui:define>			
	</ui:composition>
</html>